import requests
import json


class ListApi:

    def __init__(self):
        pass

    def list(self, token):
        headers = {
            'User-Agent': 'RestSharp/107.3.0.0',
            'Accept': 'application/json, text/json, text/x-json, text/javascript, application/xml, text/xml',
            'Content-Type': 'application/json; application/json; charset=utf-8',
            'timezone': '%2b08%3a00',
            'ipv4': '192.168.8.14',
            'Accept-Language': 'zh-CN,zh;q=1',
            'Authorization': f'bearer {token}',
        }

        json_data = {
            'groupId': None,
            'name': '',
            'pageType': 1,
            'pageDTO': {
                'page': 1,
                'size': 30,
            },
            'sortBy': '4',
        }

        response = requests.post('https://api.winrobot360.com/api/client/app/develop/list', headers=headers,
                                 json=json_data)
        try:
            json_data = response.json()
            formatted_json = json.dumps(json_data, indent=4, ensure_ascii=False)
            print("JSON Content:")
            print(formatted_json)
            return json_data
        except json.JSONDecodeError:
            print("Response is not valid JSON")


if __name__ == '__main__':
    t_access_token = '0aa9180f-8c1e-42bf-93ab-deec0e3bc737'
    ListApi().list(t_access_token)
